package com.example.back.mapper;

import com.example.back.entity.Comment;
import com.example.back.util.StringUtil;

public class CommentMapperProvider {
    public String getQueryCommentsSql(Comment comment) {
        StringBuilder sql = new StringBuilder();
        sql.append("select * from comment where 1=1");
        if (comment.getId() != null) {
            sql.append(" and id = ").append(comment.getId());
        }
        if (comment.getUserId() != null) {
            sql.append(" and userId = ").append(comment.getUserId());
        }
        if (comment.getUseredId() != null) {
            sql.append(" and useredId = ").append(comment.getUseredId());
        }
        if (StringUtil.isNotEmpty(comment.getText())) {
            sql.append(" and text like concat('%',#{text},'%') ");
        }
        if (StringUtil.isNotEmpty(comment.getTime())) {
            sql.append(" and time like concat('%',#{time},'%') ");
        }

        return sql.toString();
    }
}
